package com.ymnet.myhotupdate;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    private TextView mTextView;
    private TestBroadcastReceiver mReceiver;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mReceiver = new TestBroadcastReceiver();
        registerReceiver(mReceiver, new IntentFilter("TEST_RECEIVER"));
        mTextView = (TextView) findViewById(R.id.tv_desc);
        mTextView.setText("补丁包7代");
        Toast.makeText(this, mTextView.getText().toString(), Toast.LENGTH_SHORT).show();
    }

    public void receiver(View view) {
        Intent intent = new Intent("TEST_RECEIVER");
        sendBroadcast(intent);
    }

    public void activity(View view) {
        startActivity(new Intent(this, Main2Activity.class));
    }

    private class TestBroadcastReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals("TEST_RECEIVER")) {
                context.startActivity(new Intent(context, Main3Activity.class));
            }
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mReceiver != null) {
            unregisterReceiver(mReceiver);
        }
    }
}
